<template>
  <div class="content">
    <!--    科目列表弹窗-->
    <el-dialog
      v-dialogDrag
      :title="$t('market.subjectList')"
      model
      :visible.sync="isclientlDialog"
      :close-on-click-modal="false"
      width="60%"
      :before-close="handleClose"
    >
      <div class="header-name">
        <search
          :options="selectData"
          :search-son="searchSon"
          :msg="tacitly"
          @seek="collect"
          @hand="clientSearch"
        />
        <el-button type="primary" class="btn" size="mini" @click="clientSearch">{{ $t('btn.search') }}</el-button>
      </div>
      <div>
        <jc-table
          :table-data="clientlDialogData"
          :table-header="clientDialogHeader"
          table-height="53vh"
          serial
          @clickRow="clientlSelectRow"
        />
      </div>
      <jc-pagination
        v-show="client.total > 0"
        :total="client.total"
        :page.sync="client.pageNum"
        :limit.sync="client.pageSize"
        @pagination="queryTBdCustomerList"
      />
    </el-dialog>
  </div>
</template>
<script>
import {
  querySubjectFdocCList
} from '@/api/financial/voucher'
import {
  querySubList
} from '@/api/financial/subject'
import searData from '@/components/Search/mixin'
import search from '@/components/Search'
export default {
  components: {
    search
  },
  mixins: [searData],
  props: {
    msg: {
      type: [String, Number],
      default: ''
    }
  },
  data() {
    return {
      ftype: '89',
      // 科目列表数据分页
      isclientlDialog: true,
      client: {
        total: 0, // 总条目
        pageNum: 1, // 当前页
        pageSize: 200 // 每页显示多少条数据
      },
      clientlDialogData: [],
      clientDialogHeader: [
        { label: this.$t('market.subjectNum'), prop: 'fnumber' },
        { label: this.$t('market.subjectName'), prop: 'fname' },
        { label: this.$t('market.fmodel'), prop: 'fzjCode' }
      ],
      prodValue: { fcustId: '', fname: '', isclientlDialog: true }
    }
  },
  created() {
    this.queryTBdCustomerList()
  },
  methods: {
    // 获取科目列表
    async queryTBdCustomerList() {
      this.isclientlDialog = true
      const DATA = {
        ...this.client,
        search: this.searCollData
      }
      const api = this.msg === '2' ? querySubList : querySubjectFdocCList
      const { data: RES } = await api(DATA)
      this.clientlDialogData = RES.list
      this.client.total = RES.total
    },
    // 科目弹窗选中
    clientlSelectRow(item) {
      this.prodValue = item
      this.$emit('subject', this.prodValue)
    },
    clientSearch() {
      this.client.pageNum = 1
      this.queryTBdCustomerList()
    },
    // 关闭前回调
    handleClose() {
      this.prodValue.isclientlDialog = false
      this.$emit('subject', this.prodValue)
    }
  }
}
</script>

<style scoped lang="scss">
.content {
  @include listBom;
  .input-width {
    width: 120px;
  }
  .header-name {
    position: relative;
    width: 100%;
    margin-bottom: 15px;
    .btn {
      transform: translateY(18%);
      margin-left: 450px !important;
    }
  }
}
</style>
